package leetcode.栈;

import java.util.Stack;

//栈 先进后出 队列 先进先出
public class CQueue {
    //两个栈，一个出栈，一个入栈
    private Stack<Integer> stack1;
    private Stack<Integer> stack2;

    public CQueue() {
        stack1 = new Stack<>();
        stack2 = new Stack<>();
    }

    public void appendTail(int value) {
        stack1.push(value);
    }

    public int deleteHead() {
        if(!stack2.isEmpty()){
            return stack2.pop();
        }else{
            while(!stack1.isEmpty()){
                stack2.push(stack1.pop());
            }
            return stack2.isEmpty() ? -1 : stack2.pop();
        }
    }
    //["CQueue","appendTail","deleteHead","deleteHead","deleteHead"]
    //[[],[3],[],[],[]]
    // [null,null,3,-1,-1 ]
//["CQueue","deleteHead","appendTail","appendTail","deleteHead","deleteHead"]
//[[],[],[5],[2],[],[]]
    //[null,-1,null,null,5,2]
    public static void main(String[] args) {
        CQueue cQueue = new CQueue();
        cQueue.appendTail(3);
        int i = cQueue.deleteHead();
        int i1 = cQueue.deleteHead();
        int i2 = cQueue.deleteHead();
        System.out.println(i);
        System.out.println(i1);
        System.out.println(i2);
    }
}
